<style>
	#dialog{
		font-size: small;
	}
</style>
<script language="javascript" src="<?php echo JQUERYUI ?>jquery.ui.mouse.min.js"></script>
<script language="javascript" src="<?php echo JQUERYUI ?>jquery.ui.draggable.min.js"></script>
<script language="javascript" src="<?php echo JQUERYUI ?>jquery.ui.position.min.js"></script>
<script language="javascript" src="<?php echo JQUERYUI ?>jquery.ui.resizable.min.js"></script>
<script language="javascript" src="<?php echo JQUERYUI ?>jquery.ui.dialog.min.js"></script>
<script>
	$(document).ready(function(){
		$("#muter").hide();
		$( ".date" ).datepicker();
		$( ".date" ).datepicker( "option", "dateFormat", "dd-mm-yy");
		$( "#tanggal" ).change(function(){
			location.href = "<?php echo BIAYA ?>list_biaya_lain/"+$( this ).val();
		});
		list_table = $('#list_biaya').dataTable({
			"bFilter" : true,
			"bJQueryUI": true,
			"aLengthMenu": [[10,25,50, 100, -1], [10,25,50,100, "Semua"]],
			"sPaginationType": "full_numbers",
			"oLanguage": {
				"sLengthMenu": "Menampilkan _MENU_ data",
				"sZeroRecords": "Belum ada data reservasi yang tersimpan",
				"sInfoFiltered": "(Hasil filter dari _MAX_ yang didapat)"
			}
		});
		$( "#dialog" ).dialog({
			autoOpen: false,
			width : 800,
			height : 600,
			modal : true
		});
		$( "#tambah" ).click(function(){
			$("#dialog").dialog("open");
		});
		$('#ui-dialog-title-dialog').text('Form Penambahan Biaya Lain');
		$('#spj').change(function(){
			$("#muter").show();
			$.ajax({
                type: "GET",
                dataType: "JSON",
				url: "<?php echo BIAYA?>data_reservasi/"+$('#spj').val(),
				success: function(data)
				{
					$("#muter").hide();
					$('#nopol').val(data.no_pol);
					$('#supir').val(data.driver);
					$('#asal').val(data.asal);
					$('#tujuan').val(data.tujuan);
					$('#kapasitas').val(data.kapasitas);
					$('#penumpang').val(data.jumlah_penumpang);
					$('#penjualan_kotor').val(data.penjualan_kotor);
				}
            });
		});
	});
</script>

<?php
$data['cur_parent_menu']='pembayaran';
$data['cur_selected_menu']='biaya_lain';
$this->load->view('template/menu_view',$data);
?>
<br/><br/><br/><br/><br/><br/>
<table width="100%">
	<tr>
		<td align="center">
			Tanggal : <input type="text" id="tanggal" class="date" value="<?php echo $date?>"/>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<input id="tambah" type="button" value="Tambah Biaya Lain"/>
		</td>
	</tr>
</table>

<div id="dialog">
	<form action="<?php echo BIAYA ?>biaya_lain_process" method="post">
		<table width="700" align="center">
			<tr>
				<td width="200">
					Nomor SPJ : 
				</td>
				<td>
					<?php
						$opt = array(' '=>' ');
						for ($i = 0; $i < count($list_opt_spj); $i++) {
							$opt[$list_opt_spj[$i]['NoSPJ']] = $list_opt_spj[$i]['NoSPJ'];
						}
					?>
					<?php echo form_dropdown('no_spj', $opt,' ', 'id="spj"') ?>
					<img id="muter" src="<?php echo IMAGES?>spinner_mini.gif"/>
				</td>
			</tr>
			<tr>
				<td>
					No. Polisi : 
				</td>
				<td>
					<input type="text" name="nopol" id="nopol" readonly />
				</td>
			</tr>
			<tr>
				<td>
					Nama Supir : 
				</td>
				<td>
					<input type="text" name="supir" id="supir" readonly />
				</td>
			</tr>
			<tr>
				<td>
					Rute : 
				</td>
				<td>
					<input type="text" name="asal" id="asal" readonly /> - <input type="text" name="tujuan" id="tujuan" readonly />
				</td>
			</tr>
			<tr>
				<td>
					Tgl Pembayaran : 
				</td>
				<td>
					<input type="text" name="tgl_bayar" class="date" value="<?php echo date('m/d/Y') ?>"/>
				</td>
			</tr>
			<tr>
				<td>
					Kapasitas : 
				</td>
				<td>
					<input type="text" name="kapasitas" id="kapasitas" readonly/>
				</td>
			</tr>
			<tr>
				<td>
					Jumlah Penumpang : 
				</td>
				<td>
					<input type="text" name="penumpang" id="penumpang" readonly/>
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<hr/>
				</td>
			</tr>
			<tr>
				<td colspan="2">
			<u>Penjualan</u>
			</td>
			</tr>
			<tr>
				<td>
					Penjualan kotor : 
				</td>
				<td>
					<input type="text" name="penjualan_kotor" id="penjualan_kotor" readonly/>
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<hr/>
				</td>
			</tr>
			<tr>
				<td colspan="2">
			<u>Biaya Lain-lain</u>
			</td>
			</tr>
			<tr>
				<td colspan="2">
					<script type="text/javascript">
						function count_all(){
							sum=0;
							$('input[name="jumlah[]"]').each(function(i){
								sum+=parseInt($(this).val());
							});
							$('#total').empty();
							$('#total').text(sum);
						}
						$(" #plus ").click(function(){
							$(" #in_biaya ").append(
								'<tr>'
								+	'<td>'
								+		'&nbsp;'
								+	'</td>'
								+	'<td>'
								+		'&nbsp;'
								+	'</td>'
								+'</tr>'
								+'<tr>'
								+	'<td>'
								+		'Jenis Biaya : '
								+	'</td>'
								+	'<td>'
								+		'<select name="jenis_biaya[]">'
								<?php foreach($list_coa as $key=>$item){?>
								+			'<option value="<?php echo $key?>"><?php echo $item?></option>'	
								<?php } ?>
								+		'</select>'
								+	'</td>'
								+'</tr>'
								+'<tr>'
								+	'<td>'
								+		'Jumlah Biaya : '
								+	'</td>'
								+	'<td>'
								+		'<input type="text" name="jumlah[]" value="0"  onblur="count_all()"/>'
								+	'</td>'
								+'</tr>'
								+'<tr>'
								+	'<td>'
								+		'Jenis :' 
								+	'</td>'
								+	'<td>'
								+		'<select name="jenis[]">'
								+			'<option value="1">Kedatangan</option>'
								+			'<option value="0">Keberangkatan</option>'
								+		'</select>'
								+	'</td>'
								+'</tr>'
							);
						});
					</script>
					<table id="in_biaya">
						<tr>
							<td>
								Jenis Biaya : 
							</td>
							<td>
								<?php echo form_dropdown('jenis_biaya[]', $list_coa)?>
							</td>
						</tr>
						<tr>
							<td>
								Jumlah Biaya : 
							</td>
							<td>
								<input type="text" name="jumlah[]"  value="0" onblur="count_all()"/>
							</td>
						</tr>
						<tr>
							<td>
								Jenis : 
							</td>
							<td>
								<select name="jenis[]">
									<option value="1">Kedatangan</option>
									<option value="0">Keberangkatan</option>
								</select>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<span id="plus">Tambah Item</span>
				</td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					Total Biaya Lain-lain :  <span id="total">0</span>
				</td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<hr/>
				</td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<input type="submit" value="Masukkan Biaya"/>
				</td>
			</tr>
		</table>
	</form>
</div>
<div class="maia-aux">
<table id="list_biaya" width="100%">
	<thead>
		<th>
			No
		</th>
		<th>
			No. SPJ
		</th>
		<th>
			No. Polisi
		</th>
		<th>
			Supir
		</th>
		<th>
			Jenis Biaya
		</th>
		<th>
			Jumlah
		</th>
		<th>
			Cabang Bayar
		</th>
		<th>
			Kasir
		</th>
		<th>
			Aksi
		</th>
	</thead>
<tbody>
	<?php for ($i = 0; $i < count($list_biaya); $i++) { 
            if($list_biaya[$i]['jumlah'] >0)
            {
            ?>
	<tr>
	<td><?php echo ($i + 1) ?></td>
	<td><?php echo $list_biaya[$i]['NoSPJ'] ?></td>
	<td><?php echo $list_biaya[$i]['NoPol'] ?></td>
	<td><?php echo $list_biaya[$i]['Driver'] ?></td>
	<td><?php echo $list_biaya[$i]['nama_coa'] ?></td>
	<td><?php echo $list_biaya[$i]['jumlah'] ?></td>
	<td><?php echo $list_biaya[$i]['cabang'] ?></td>
	<td><?php echo $this->user->get_name($list_biaya[$i]['idkasir']) ?></td>
	<td><a href="<?php echo BIAYA?>cetak/<?php echo $list_biaya[$i]['id']?>" target="_blank">Cetak</a></td>
	</tr>
<?php }} ?>
</tbody>
</table>
</div>
<center><a href="<?php echo HOME?>">Kembali</center>